<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="名称" prop="name"
                :rules="[
                  {required: true, message:'名称不能为空', trigger:'blur'}
                 ]">
			        <el-input v-model="inputForm.name" placeholder="请填写名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="排序" prop="sort"
                :rules="[
                  {required: true, message:'排序不能为空', trigger:'blur'},
                  {validator: validator.isNumber, trigger:'blur'}
                 ]">
			        <el-input v-model="inputForm.sort" placeholder="请填写排序"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12" v-if="hasPermission('smis:system')">
            <el-form-item label="系统类型" prop="osType"
                :rules="[
                 ]">
                    <el-radio-group v-model="inputForm.osType">
                        <el-radio v-for="item in $dictUtils.getDictList('os_type')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
                    </el-radio-group>
           </el-form-item>
        </el-col>
        <el-col :span="12" v-if="hasPermission('smis:system')">
            <el-form-item label="设备类型" prop="devType"
                :rules="[
                 ]">
                    <el-radio-group v-model="inputForm.devType">
                        <el-radio v-for="item in $dictUtils.getDictList('dev_type')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
                    </el-radio-group>
           </el-form-item>
        </el-col>
        <el-col :span="12" v-if="hasPermission('smis:system')">
             <el-form-item label="开机时间" prop="shutupTime"
                 :rules="[
                  ]">
                <el-time-select
                  placeholder="开机时间"
                  v-model="inputForm.shutupTime"
                  :picker-options="{
                    start: '00:00',
                    step: '00:05',
                    end: '23:59'
                  }">
                </el-time-select>
            </el-form-item>
         </el-col>
         <el-col :span="12">
             <el-form-item label="关机时间" prop="shutdownTime"
                 :rules="[
                  ]">
                  <el-time-select
                    placeholder="关机时间"
                    v-model="inputForm.shutdownTime"
                    :picker-options="{
                      start: '00:00',
                      step: '00:05',
                      end: '23:59'
                    }">
                  </el-time-select>
            </el-form-item>
         </el-col>
        <el-col :span="12">
            <el-form-item label="解锁密码" prop="unlockPwd"
                :rules="[
                 ]">
              <el-input v-model="inputForm.unlockPwd" placeholder="请填写解锁密码"     ></el-input>
           </el-form-item>
        </el-col>
			
        <el-col :span="12">
            <el-form-item label="回到首页(秒)" prop="returnIndexTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.returnIndexTime" placeholder="请填写回到首页(秒)"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12" v-if="hasPermission('smis:system')">
          <el-form-item label="程序版本" prop="version"
              :rules="[
             ]">
            <el-input v-model="inputForm.version" placeholder="请填写程序版本"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="22" v-if="hasPermission('smis:system')">
          <el-form-item label="程序文件" prop="versionFile"
                        :rules="[

               ]">
            <el-upload-ext
              :limit = "1"
              accept = ".zip,.wgt,.apk"
              fileType = "1"
              :allowOtherSize = "false"
              :allowScale = "true"
              v-model = "inputForm.versionFile"
            >
              </el-upload-ext>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="hasPermission('smis:system')">
            <el-form-item label="二维码" prop="qrcodeUrl"
                :rules="[
                 ]">
              <el-input v-model="inputForm.qrcodeUrl" placeholder="请填写二维码地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="包含游戏" prop="detail"
                :rules="[
                 ]">
						 <el-radio-group v-model="inputForm.detail">
						     <el-radio v-for="item in $dictUtils.getDictList('yes_no')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
						 </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import ElUploadExt from '@/components/elUploadExt'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          parent: {
            id: ''
          },
          name: '',
          sort: '',
          shutupTime: '',
          shutdownTime: '',
          osType: '',
          devType: '',
          returnIndexTime: '',
          unlockPwd: '',
          version: '',
          versionFile: '',
          detail: '0',
          qrcodeUrl: ''
        }
      }
    },
    components: {
      ElUploadExt
    },
    methods: {
      init (method, obj) {
        this.method = method
        this.inputForm.id = obj.id
        if (method === 'add') {
          this.title = '新建设备组'
        } else if (method === 'addChild') {
          this.title = '添加下级设备组'
        } else if (method === 'edit') {
          this.title = '修改设备组'
        } else if (method === 'view') {
          this.title = '查看设备组'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.inputForm.parent.id = obj.parent.id
          this.inputForm.parent.name = obj.parent.name
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/smis/kiosk/jfKioskGroup/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.jfKioskGroup)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/smis/kiosk/jfKioskGroup/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshTree')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>
